package cs275.ants.agent;

import java.util.List;

import com.google.common.collect.Lists;

import cs275.ants.graph.base.Graph;
import cs275.ants.graph.base.GraphVertex;

public class AntManager {
	private List<Ant> ants;
	public AntManager(List<Ant> ants) {
		this.ants = ants;
	}
	
	public static AntManager withAnts(int numAnts, Graph graph, GraphVertex currentPosition) {
		return new AntManager(createAnts(numAnts, graph, currentPosition));
	}
	
	public void moveAllAnts() {
		for(Ant ant : ants) {
			GraphVertex nextVertex = ant.chooseNextMove();
			ant.move(nextVertex);
		}
	}

	public void addAnts(int numAnts, Graph graph, GraphVertex currentPosition) {
		for(int i=0;i<numAnts;i++) {
			ants.add(new Ant(graph, currentPosition));
		}
	}

	public List<Ant> getAnts() {
		return ants;
	}

	private static List<Ant> createAnts(int numAnts, Graph graph, GraphVertex currentPosition) {
		List<Ant> newAnts = Lists.<Ant>newArrayListWithCapacity(numAnts);
		for(int i=0;i<numAnts;i++) {
			newAnts.add(new Ant(graph, currentPosition));
		}
		return newAnts;
	}
}
